// user.js
var api = require('../../api.js');
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        rules_withdrawals: null,
        // 按钮颜色切换
        btn_background: false,
        inputNum: '',
        user_money: null
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var page = this;
        page.setData({
            inputNum: ''
        })
        //    获取用户详细提现提示
        page.changeInfo();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },
    // 获取提现规则
    changeInfo() {
        var page = this;
        app.request({
            url: api.default.rules_withdrawals,
            data: {
                // uid: wx.getStorageSync("user_info").user_id
                token: app.globalData.token,
            },
            success: function (res) {
                if (res.code == 1) {
                    page.setData({
                        rules_withdrawals: res.data,
                        user_money: res.data.user_money
                    })
                }
            }
        });
    },
    // 用户输入提现金额
    begin_input(e) {
        var page = this;
        // var reg=/^\d+(\.\d{0,2})?$/;
        var money = e.detail.value
        if (e.detail.value) {
            page.setData({
                btn_background: true,
                btn_money: money,
            })
        } else {
            page.setData({
                btn_background: false,
                btn_money: '',
            })
        }
    },
    finished_input() {
        // console.log(e.detail.value,'输入完毕')
        // var page=this;
        // page.setData({

        // })
    },
    // 全部提现
    all_withdrawDeposit() {
        var page = this
        page.setData({
            btn_money: page.data.user_money
        })
    },
    // 提现到钱包
    tobag() {
        var page = this;
        var reg = /^\d+(\.\d{0,2})?$/;
        if (!page.data.btn_money) {
            wx.showToast({
                title: '请输入提现金额',
                icon: 'none',
                duration: 1000,
            });
        } else if (!reg.test(page.data.btn_money)) {
            wx.showToast({
                title: '请输入正确的金额',
                icon: 'none',
                duration: 1000,
            });
        } else {
            page.ImmediatelyWithdraw();
        }
    },
    // 马上提现
    ImmediatelyWithdraw() {
        var page = this;
        var money = page.data.btn_money
        app.request({
            url: api.default.rules_withdrawals,
            data: {
                // uid: wx.getStorageSync("user_info").user_id,
                token: app.globalData.token,
                money: money
            },
            method: 'POST',
            header: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            success: function (res) {
              console.log(res);
                if (res.code == 1) {
                  wx.redirectTo({
                    url: '/pages/withdrawDeposit-list/withdrawDeposit-list',
                  })
                }
                wx.showToast({
                    title: res.msg,
                    icon: 'none',
                    duration: 1000,
                });

            }
        });
    },
    getOrderCountData: function () {

    },
    onPullDownRefresh: function () {

    }
});